package com.yt.generator.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * @Description ：
 * @Author ： 解风
 * @Date ： 2017/11/24 17:21
 */
@ApiModel
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "响应码", required = true)
    private int code = CodeEnum.SUCCESS.getCode();//响应码，默认成功

    @ApiModelProperty(value = "响应消息", required = true)
    private String msg = CodeEnum.SUCCESS.getMsg();//响应消息

    @ApiModelProperty(value = "结果对象", required = true)
    private T data = null;//结果对象


    /**
     * 是否成功
     * @return
     */
    public boolean success(){
        return code == CodeEnum.SUCCESS.getCode();
    }

    public Result(CodeEnum codeEnum){
        this(codeEnum.getCode(),codeEnum.getMsg());
    }
    public Result(CodeEnum codeEnum, T data){
        this(codeEnum.getCode(),codeEnum.getMsg(), data);
    }
    public Result(int code) {
        this.code = code;
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public Result(T data) {
        this.data = data;
    }
    public Result() {

    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
